let preModules = {
  "vue-axios": {
    "views": [],
    "components": [],
    "assets": [],
    "static": [],
    "dependencies": { "axios": "^0.24.0", "vue-axios": "^3.4.0" },
    "dev_dependencies": {}
  },
  "element-ui": {
    "views": ["Index.vue", "Error.vue"],
    "components": ["BaseHeader.vue"],
    "assets": ["element_styles", "element_ui"],
    "static": ["json/food_demo.json"],
    "dependencies": { "element-ui": "^2.15.6" },
    "dev_dependencies": { "babel-plugin-component": "^1.1.1" }
  },
  "vue-awesome": {
    "views": ["AweSome.vue"],
    "components": [],
    "assets": ["awesome"],
    "static": [],
    "dependencies": { "vue-awesome": "^3.0.5" },
    "dev_dependencies": {}
  },
  "echarts": {
    "views": ["Echarts.vue"],
    "components": [],
    "assets": [],
    "static": [],
    "dependencies": { "echarts": "^5.0.0-beta.2" },
    "dev_dependencies": {}
  }
}

module.exports = (api, options, rootOptions) => {
  api.render('./template');
  let dependencies = {};
  let dev_dependencies = {};
  for (let module of options.modules) {
    for (let item in preModules[module].dependencies)
      dependencies[item] = preModules[module].dependencies[item];
    for (let item in preModules[module].dev_dependencies)
      dev_dependencies[item] = preModules[module].dev_dependencies[item];
  }
  api.render(files => {
    Object.keys(files)
      .filter(file => {
        let flag = false;
        for (let module in preModules) {
          if (!options.modules.includes(module)){
            flag = flag || preModules[module].views.some(it => {
              return file == "src/views/" + it;
            }) || preModules[module].components.some(it => {
              return file == "src/components/" + it;
            }) || preModules[module].assets.some(it => {
              return file.startsWith("src/assets/" + it);
            }) || preModules[module].static.some(it => {
              return file.startsWith("src/static/" + it);
            });
          }
        }
        if (options.modules.includes("element-ui") && file.startsWith("src/assets/element_styles/") && !file.startsWith(`src/assets/element_styles/${options.theme}/`))
          flag = true;
        return flag;
      })
      .forEach(path => delete files[path])
  });
  api.extendPackage({
    "name": rootOptions.projectName,
    "dependencies": dependencies,
    "devDependencies": dev_dependencies
  })
}